﻿<Page x:Class="SlotDuino.UI.Pages.TrackConfig"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
      xmlns:dal="clr-namespace:SlotDuino.DAL;assembly=SlotDuino.DAL"
      xmlns:converter="clr-namespace:SlotDuino.Converter"
      mc:Ignorable="d"
      Background="{x:Null}"
	Title="TrackConfig" Loaded="Page_Loaded" DataContext="{Binding RelativeSource={RelativeSource Self}}">

    <Page.Resources>
        <CollectionViewSource x:Key="slotsViewSource" Source="{Binding Path=Track.Slots}" d:DesignSource="{d:DesignInstance dal:Slot, CreateList=True}"/>
        <CollectionViewSource x:Key="voltagesViewSource" Source="{Binding Path=Track.Voltages}" d:DesignSource="{d:DesignInstance dal:Voltage, CreateList=True}"/>
        <converter:TimeSpanToLaptime x:Key="TimeSpanToLaptime" />
        <converter:EntityStateToBoolean x:Key="EntityStateToBoolean" />
    </Page.Resources>

    <StackPanel DataContext="{Binding Path=Track}">
    	<GroupBox Header="Dados Básicos" Margin="0,0,0,10" MinWidth="450" Height="130">
    		<Grid>
    			<Label Content="Nome da Pista" Margin="8,8,0,0" d:LayoutOverrides="HorizontalAlignment" HorizontalAlignment="Left" VerticalAlignment="Top" />
    			<TextBox x:Name="txtTrackName" TabIndex="1" Text="{Binding Name, Mode=TwoWay, NotifyOnValidationError=True, ValidatesOnDataErrors=True, ValidatesOnExceptions=True}" VerticalAlignment="Top" Margin="7.999,27.274,0,0" HorizontalAlignment="Left" Width="313.644" />
    			<Label Content="Comprimento (cm)" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="338.643,8,0,0" />
    			<TextBox x:Name="txtTrackLenght" TabIndex="2" Text="{Binding Length, Mode=TwoWay, NotifyOnValidationError=True, ValidatesOnDataErrors=True, ValidatesOnExceptions=True}" HorizontalAlignment="Left" Margin="338.643,27.274,0,0" VerticalAlignment="Top" Width="59.356"/>
    			<Label 	Content="Tempo mínimo" HorizontalAlignment="Left" Margin="7.999,55.88,0,0" VerticalAlignment="Top" />
    			<TextBox x:Name="txtMinTime" TabIndex="3" Text="{Binding MinLapTime, Converter={StaticResource TimeSpanToLaptime}, Mode=TwoWay, NotifyOnValidationError=True, ValidatesOnDataErrors=True, ValidatesOnExceptions=True}" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="8.001,76.114,0,0" Width="50" />
    			<Label Content="segundos" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="61.998,81.114,0,0"/>
    			<Label 	Content="Tempo máximo" Margin="137,55.88,0,0" HorizontalAlignment="Left" VerticalAlignment="Top" />
    			<TextBox x:Name="txtMaxTime"  TabIndex="4" Text="{Binding MaxLapTime, Converter={StaticResource TimeSpanToLaptime}, Mode=TwoWay, NotifyOnValidationError=True, ValidatesOnDataErrors=True, ValidatesOnExceptions=True}" VerticalAlignment="Top" Margin="137.001,76.114,0,0" HorizontalAlignment="Left" Width="50" />
    			<Label Content="segundos" Margin="191,81.114,0,0" VerticalAlignment="Top" HorizontalAlignment="Left" />
    		</Grid>

    	</GroupBox>
    	<UniformGrid Margin="0,0,0,10" MinHeight="200" Rows="1"  >
    		<GroupBox Header="Fendas">
    			<Grid>
    				<Grid.RowDefinitions>
    					<RowDefinition Height="35"/>
    					<RowDefinition/>
    				</Grid.RowDefinitions>
    				<Label x:Name="lblNumLanes" Content="Numero de Fendas" HorizontalAlignment="Left" Margin="8,8,0,8.723" d:LayoutOverrides="Height" />
                    
    				<ComboBox x:Name="cmbNumSlots" TabIndex="5" Padding="4,3" IsReadOnly="True" SelectionChanged="cmbNumLanes_SelectionChanged" RenderTransformOrigin="3.718,-1.018" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="103.606,5,0,0">
    					<ComboBoxItem Content="1" IsSelected="True" />
    					<ComboBoxItem Content="2"/>
    					<ComboBoxItem Content="3"/>
    					<ComboBoxItem Content="4"/>
    					<ComboBoxItem Content="5"/>
    					<ComboBoxItem Content="6"/>
    					<ComboBoxItem Content="7"/>
    					<ComboBoxItem Content="8"/>
    				</ComboBox>

    				<DataGrid CanUserAddRows="False" AutoGenerateColumns="False" Background="{StaticResource SelectedBackgroundBrush}" x:Name="lanesDataGrid" ItemsSource="{Binding Source={StaticResource slotsViewSource}}" Grid.Row="1" TabIndex="6">
    					<DataGrid.Columns>
    						<DataGridTextColumn x:Name="laneId" Binding="{Binding Id}" Header="Id" IsReadOnly="True" />
    						<DataGridTextColumn x:Name="cmbLaneColor" Binding="{Binding Color}" Header="Cor"/>
    					</DataGrid.Columns>
    				</DataGrid>
    			</Grid>
    		</GroupBox>

    		<GroupBox Header="Controle de Tensão" Margin="5,0,0,0">
    			<Grid>
    				<Grid.RowDefinitions>
    					<RowDefinition Height="35"/>
    					<RowDefinition/>
    				</Grid.RowDefinitions>
    				<ComboBox  x:Name="cmbVoltage" HorizontalAlignment="Left" SelectionChanged="cmbVoltage_SelectionChanged" VerticalAlignment="Top" Margin="8,7.723,0,0" TabIndex="7">
    					<ComboBoxItem Content="Desativado" IsSelected="True" />
    					<ComboBoxItem Content="2 tensões"/>
    					<ComboBoxItem Content="4 tensões"/>
    				</ComboBox>

    				<DataGrid CanUserAddRows="False" AutoGenerateColumns="False" Background="{StaticResource SelectedBackgroundBrush}" x:Name="voltageDataGrid" ItemsSource="{Binding Source={StaticResource voltagesViewSource}}" Grid.Row="1" TabIndex="8">
    					<DataGrid.Columns>
                            <DataGridTextColumn  Header="Id" Binding="{Binding Id}" IsReadOnly="True" />
    						<DataGridTextColumn  Header="Tensão" Binding="{Binding Label}" />
                            <DataGridTextColumn  Header="Padrão" Binding="{Binding Default}" />
    					</DataGrid.Columns>
    				</DataGrid>
                    
    			</Grid>
    		</GroupBox>

    	</UniformGrid>
        <StackPanel Orientation="Horizontal" HorizontalAlignment="Right" >
            <Button   Content="Cancelar" Height="32" 	x:Name="btnCancel" 	VerticalAlignment="Top" Width="80" HorizontalAlignment="Right" IsCancel="True" Command="NavigationCommands.BrowseBack" Click="btnCancel_Click" TabIndex="9" />
            <Button   Content="Salvar" Height="32" 	x:Name="btnSave" 	VerticalAlignment="Top" Width="80" HorizontalAlignment="Right" Margin="10,0,0,0" IsDefault="True" Click="btnSave_Click" IsEnabled="{Binding Path=EntityState, Converter={StaticResource EntityStateToBoolean}, ConverterParameter=Modified}" TabIndex="10" />
        </StackPanel>
    </StackPanel>
</Page>
